package com.thzy.bbs.callBacks;

import android.util.Log;

import com.thzy.bbs.activity.MainActivity;
import com.thzy.bbs.common.AddressConfig;
import com.thzy.bbs.common.Constants;
import com.thzy.bbs.thread.PhotoUploadingThread;

import java.util.ArrayList;
import java.util.List;

import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.model.PhotoInfo;

/**
 * 自定义相册回调处理
 *
 * @author Lirui
 * @date 2017/1/4 15:34
 */

public class PhotoCallBack implements GalleryFinal.OnHanlderResultCallback {
    /**
     * userId(头像上传需要识别用户)
     */
    private String userId = null;

    public PhotoCallBack(String userId) {
        this.userId = userId;
    }

    @Override
    public void onHanlderSuccess(int requestCode, List<PhotoInfo> resultList) {
        String url;
        if (requestCode == Constants.Code.PHOTO_HAND_CODE) {
            url = AddressConfig.ConfigAddress.IMAGE_HAND_URL;
        } else {
            url = AddressConfig.ConfigAddress.IMAGE_URL;
        }
        //上传图片
        MainActivity.isUploading = true;
        /**
         * 1.需要处理带有返回参数的跳转
         * 2.返回上传消息（上传后的地址）
         */
        List<String> bas = new ArrayList<>(resultList.size());
        bas.add(AddressConfig.ConfigAddress.IMAGE_HAND_URL);
        for (PhotoInfo photoInfo : resultList) {
            Log.e("照片地址：", photoInfo.getPhotoPath());
            bas.add(photoInfo.getPhotoPath());
        }
        new Thread(new PhotoUploadingThread(resultList, url, userId)).start();
    }

    @Override
    public void onHanlderFailure(int requestCode, String errorMsg) {

    }


}
